#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <vector>
#include <set>
#include <queue>

using namespace std;
using LL = long long;
using PII = pair<int, int>;

const int N = 40;

int n;
int g[N][N];
bool st[N][N];
int dis[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

void dfs(int x, int y){
    st[x][y] = true;

    for(int i = 0; i < 4; i ++){
        int nx = x + dis[i][0], ny = y + dis[i][1];
        if(nx < 1 || nx > n || ny < 1 || ny > n) continue;
        if(st[nx][ny]) continue;
        if(g[nx][ny] == 1) continue;

        dfs(nx, ny);
    }
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= n; j ++){
            cin >> g[i][j];
        }
    }

    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= n; j ++){
            if((i == 1 || j == 1 || i == n || j == n) && !st[i][j] && g[i][j] == 0){
                dfs(i, j);
            }
        }
    }

    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= n; j ++){
            if(!st[i][j] && g[i][j] == 0) g[i][j] = 2;
        }
    }


    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= n; j ++){
            cout << g[i][j] << " ";
        }
        cout << '\n';
    }




    return 0;
}